package ink.metoo.auto.fishpi.chatroom.command

import ink.metoo.auto.fishpi.Log
import ink.metoo.auto.fishpi.call.ChatRoomCall
import ink.metoo.auto.fishpi.chatroom.Message
import ink.metoo.auto.fishpi.chatroom.RedPacket
import org.apache.commons.lang3.math.NumberUtils

class SendSpecifyRedPacketCommand : SendRedPacketCommand(RedPacket.Type.SPECIFY) {

    override fun execute(message: Message) {
        val params = message.commandParams
        val name = params.getOrNull(1) ?: return
        val money = NumberUtils.toInt(params.getOrNull(2), 32).coerceAtLeast(32)
        val result = ChatRoomCall.sendRedPacket {
            it.msg = params.getOrNull(3) ?: "给${name}的${type.description}"
            it.money = money
            it.count = 1
            it.recivers = arrayListOf(name)
            it.type = type.value
        }
        Log.info("向${name}发送了${money}${type.description}, 发送结果: ${result.code == 0}")
    }

}